﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using Entidades;

namespace ProyectoCine.AreaPrivada
{
    public partial class WebForm2 : System.Web.UI.Page, IGrilla
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ViewState["Orden"] = "";
                gvCine.DataKeyNames = new string[] { "id_Cine" };
                cargarGrilla();
            }
        }

        protected void gvCine_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gvCine.SelectedIndex == -1) return;
            Session["id_CineEdicion"] = gvCine.SelectedDataKey.Value;
            Response.Redirect("AltaCine.aspx");
        }

        protected void gvCine_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["Orden"] = e.SortExpression;
            cargarGrilla();
        }

        public void cargarGrilla()
        {
            gvCine.DataSource = CineDAO.CargarGrilla(ViewState["Orden"].ToString());
            gvCine.DataBind();
        }

        protected void gvCine_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvCine.PageIndex = e.NewPageIndex;
            cargarGrilla();            
        }

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBuscar.Text))
            {
                gvCine.DataSource = CineDAO.cargarGrillaNombre(txtBuscar.Text);
                gvCine.DataBind();
            }
            else
            {
                cargarGrilla();
            }
        }
    }
}